package br.com.sgi.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="USERS_IGREJA")
@NamedQueries({
	@NamedQuery(
	    name="buscarUserIgrejaPorUser",
	    query="SELECT ui FROM UsersIgreja ui " +
	    	  " WHERE ui.users.sistema.coSeqSistema =:coSistema" +
	    	  " AND ui.users.username =:username"
	),
	@NamedQuery(
		    name="buscarUserIgrejaCoIgreja",
		    query="SELECT ui FROM UsersIgreja ui " +
		    	  " WHERE ui.users.sistema.coSeqSistema =:coSistema" +
		    	  " AND ui.igreja.coSeqIgreja =:coIgreja"
		)
//@NamedQuery(name="buscarCoUsersIgrejaPorUsername",
//		    query=" SELECT ui.coSeqUsersIgreja FROM UsersIgreja ui " +
//		    	  " WHERE ui.sistema.coSeqSistema =:coSistema " +
//		    	  " ui.users.username =:username"
//)
})

public class UsersIgreja {
	
	@Id
	@Column(name="CO_SEQ_USERS_IGREJA")
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "seq_usersigreja_sequsersigrejaa")  
	@SequenceGenerator(name = "seq_usersigreja_sequsersigrejaa", sequenceName = "SGI.seq_usersigreja")
	private Long coSeqUsersIgreja;
	
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="USERNAME")
	private Users users;
	
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="CO_IGREJA")
	private Igreja igreja;

	public Long getCoSeqUsersIgreja() {
		return coSeqUsersIgreja;
	}

	public void setCoSeqUsersIgreja(Long coSeqUsersIgreja) {
		this.coSeqUsersIgreja = coSeqUsersIgreja;
	}

	public Users getUsers() {
		return users;
	}

	public void setUsers(Users users) {
		this.users = users;
	}

	public Igreja getIgreja() {
		return igreja;
	}

	public void setIgreja(Igreja igreja) {
		this.igreja = igreja;
	}

}
